<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>查询评价</title>
    <link href="../css/evaluation/evaluation.css" rel="stylesheet" type="text/css"/>
    <link href="../css/jquery/jquery-ui-1.8.23.custom.css" rel="stylesheet" type="text/css"/>
    <link href="../css/jw/jw.css" rel="stylesheet" type="text/css"/>
    <script src="../js/jquery/jquery-1.8.0.min.js"></script>
    <script src="../js/jquery/jquery-ui-1.8.23.custom.min.js"></script>
    <script src="../js/util.js"></script>
    <script src="../js/jw/jw.js"></script>
    <script type="application/javascript">
        $(function () {
            var declarationTypeTags = [{label: "进口", value: "I"}, {label: "出口", value: "E"}];
            $("#declaration_type_show").autocomplete({
                                                         minLength: 0,
                                                         source: declarationTypeTags,
                                                         focus: function (event, ui) {
                                                             $("#declaration_type_show").val(
                                                                     ui.item.label);
                                                             return false;
                                                         },
                                                         select: function (event, ui) {
                                                             $("#declaration_type_show").val(
                                                                     ui.item.label);
                                                             $("#declaration_type").val(
                                                                     ui.item.value);
                                                             return false;
                                                         }
                                                     });
            $("#declaration_type_show").on("click", function () {
                $("#declaration_type_show").autocomplete("search", "");
            });

            $("#customer_com_name").autocomplete({
                                                     minLength: 1,
                                                     autoFocus: true,
                                                     matchContains: true,
                                                     source: function (request, response) {
                                                         var data = {
                                                             k: $("#customer_com_name").val()
                                                         };
                                                         $.ajax({
                                                                    url: "../base/dropdown-company?tdateaa="
                                                                         + timeNum(),
                                                                    data: data,
                                                                    success: function (data) {
                                                                        response($.map(data,
                                                                                       function (item) {
                                                                                           return {
                                                                                               key: item[1],
                                                                                               value: item[0]
                                                                                           }
                                                                                       }));
                                                                    }
                                                                });
                                                     }, select: function (event, ui) {
                    $("#customer_com_id").val(ui.item.key);
                    $("#customer_com_name").val(ui.item.value);
                    return false;
                }
                                                 });

            var pageNo = "${pageNo}" ? "${pageNo}" : 1;
            $("#currentPage").attr("placeholder", pageNo);
            $("#currentPage").on("keypress", function () {
                if (event.keyCode == 13) {
                    gotoPage($(this).val());
                }
            });
        });

        var url = "./main?";
        function doQuery() {
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            window.location.href = url;
        }

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        function gotoFirst() {
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            window.location.href = url + "&pageNo=1";
        }

        function gotoLast() {
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            window.location.href = url + "&pageNo=" +${totalPages};
        }

        function gotoPrevious() {
            var pageNo = "${pageNo}";
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            if (pageNo) {
                url += "&pageNo=" + ((parseInt(pageNo) - 1) < 1 ? 1 : (parseInt(pageNo) - 1));
            }
            window.location.href = url;
        }

        function gotoNext() {
            var pageNo = "${pageNo}";
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            if (!pageNo) {
                pageNo = 1;
            }
            url += "&pageNo=" + ((parseInt(pageNo) + 1) > parseInt('${totalPages}'
                    ) ? ${totalPages} : (parseInt(pageNo) + 1));
            window.location.href = url;
        }

        function gotoPage(pageNo) {
            if (!pageNo || pageNo >${totalPages} || pageNo < 1) {
                alert("错误的页码!");
                return;
            }
            var businessId = $("#businessId").val();
            var SNO = $("#SNO").val();
            var declaration_type = $("#declaration_type").val();
            var customer_com_id = $("#customer_com_id").val();
            var customer_com_name = $("#customer_com_name").val();
            if (businessId) {
                url += "&businessId=" + businessId;
            }
            if (SNO) {
                url += "&SNO=" + SNO;
            }
            if (declaration_type) {
                url += "&declaration_type=" + declaration_type;
            }
            if (customer_com_id) {
                url += "&customer_com_id=" + customer_com_id;
            }
            if (customer_com_name) {
                url += "&customer_com_name=" + customer_com_name;
            }
            window.location.href = url + "&pageNo=" + pageNo;
        }

        function gotoEditPage(relationId, evalId, evaluationRecordId) {
            if (!relationId || !evalId) {
                alert("缺少参数，请与管理员联系！");
                return;
            }
            jw.dialog({
                          iframe: "./edit?relationId=" + relationId + "&evalId=" + evalId
                                  + "&evaluationRecordId=" + evaluationRecordId,
                          width: 800,
                          height: 570
                      });
        }
    </script>
</head>

<body>
<div class="evaluationQuery">
    <table class="tableWidth">
        <tr>
            <td class="business">业务编号：</td>
            <td class="queryInput"><input id="businessId" value="${businessId}"/>
            </td>
            <td class="declaration">报关单号：</td>
            <td class="queryInput"><input id="SNO" value="${SNO}"/></td>
            <td class="queryEmpty"></td>
        </tr>
        <tr>
            <td class="business">业务类型：</td>
            <td class="querySelect">
                <input id="declaration_type_show" value="${declaration_type_show}"
                       style="width: 100%;height: 24px;border: 1px solid #3c763d;}"/>
                <input id="declaration_type" value="${declaration_type}" type="hidden">
            </td>
            <td class="declaration">客户：</td>
            <td class="querySelect">
                <input id="customer_com_name" value="${customer_com_name}"
                       style="width: 100%;height: 24px;border: 1px solid #3c763d;}"/>
                <input id="customer_com_id" value="${customer_com_id}" type="hidden"/>
            </td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="queryBtn">
                <button onclick="javascript:doQuery();">查询</button>
            </td>
            <td></td>
        </tr>
    </table>
</div>
<div class="evaluationWidth" id="evaCont">
    <table class="tableWidth" cellspacing="0" cellpadding="0">
        <c:set var="evalScoreCoverStr" value="很不满意,,不满意,一般,满意,很满意"/>
        <c:set var="delim" value=","/>
        <c:set var="evalScoreCoverArr" value="${fn:split(evalScoreCoverStr, delim)}"/>
        <c:forEach var="dec" items="${declarationList}">

            <c:if test="${not empty dec.evaluation.evaluationRecords}">
                <tr>
                    <td rowspan="2" class="company">
                        <h3>${dec.customer.name}：</h3>
                        <p>（${dec.businessId}）</p>
                        <p>（${dec.sno}）</p>
                    </td>
                    <td colspan="2" class="comments"><p>
                            ${dec.evaluation.evaluationRecords[0].evalContent}</p>
                    </td>
                    <td class="replyComment">
                        <c:if test="${fn:length(dec.evaluation.evaluationRecords) lt 2}">
                            <a href="javascript:;"
                               onclick="javascript:gotoEditPage('${dec.id}','${dec.evaluation.evalId}','${dec.evaluation.evaluationRecords[0].recordId}');">回复评论</a>
                        </c:if>
                    </td>
                </tr>
                <tr>
                    <td class="commentTime"><fmt:formatDate
                            value="${dec.evaluation.evaluationRecords[0].evalTime}"
                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    <td class="satisfaction">
                        <span>${evalScoreCoverArr[dec.evaluation.evalScore]}</span>
                    </td>
                    <td class="mark">
                        <c:if test="${dec.declaration_type eq 'E'}"> 出口 </c:if>
                        <c:if test="${dec.declaration_type eq 'I'}"> 进口 </c:if>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div class="dottedLine"></div>
                    </td>
                </tr>
                <c:forEach var="record" items="${dec.evaluation.evaluationRecords}" varStatus="it">
                    <c:if test="${!it.first}">
                        <c:choose>
                            <c:when test="${it.count % 2 eq 1}">
                                <tr class="replyBg">
                                    <td class="reply">追评</td>
                                    <td colspan="2" class="replyTime"><fmt:formatDate
                                            value="${record.evalTime}"
                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                    <td class="replyComment">
                                        <c:if test="${it.last && it.count lt 4}">
                                            <a class="review" href="javascript:;"
                                               onclick="javascript:gotoEditPage('${dec.id}','${dec.evaluation.evalId}','${record.recordId}');">回复</a>
                                        </c:if>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" class="replyContent1">
                                        <p>
                                                ${record.evalContent}</p>
                                    </td>
                                </tr>
                            </c:when>
                            <c:otherwise>
                                <tr class="replyBg">
                                    <td class="reply">回复</td>
                                    <td colspan="2" class="replyTime"><fmt:formatDate
                                            value="${record.evalTime}"
                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                    <td class="replyComment">
                                            <%--<c:if test="${it.last && it.count lt 4}">
                                                <a class="review" href="javascript:;"
                                                   onclick="javascript:gotoEditPage('${dec.id}','${dec.evaluation.evalId}');">追评</a>
                                            </c:if>--%>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" class="replyContent">
                                        <p>
                                                ${record.evalContent}</p>
                                    </td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                    </c:if>
                </c:forEach>
                <tr>
                    <td colspan="4">
                        <div class="solidLine"></div>
                    </td>
                </tr>
            </c:if>
        </c:forEach>
    </table>
</div>
<div class="pageNumber">
    <ul>
        <li class="lastPage">
            <a href="javascript:;" onclick="javascript:gotoLast();">最后一页</a>
        </li>
        <li class="nextPage">
            <a href="javascript:;" onclick="javascript:gotoNext();">下一页</a>
        </li>
        <li class="enterPage">
            <input id="currentPage" placeholder="1"/>
        </li>
        <li class="previousPage">
            <a href="javascript:;" onclick="javascript:gotoPrevious();">上一页</a>
        </li>
        <li class="homePage">
            <a href="javascript:;" onclick="javascript:gotoFirst();">首页</a>
        </li>
    </ul>
</div>
</body>
</html>
